﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZS_YUESHENBAOControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            if (!base.Page.IsPostBack) {
                BindData();
            }
            CustomGridView CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            CustomGridList1.OnLoadData += new EventHandler(CustomGridList1_OnLoadData);
        }

        protected void BindData()
        {
            CustomGridView CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            DataTable dt = _EluZSDataProvider.GetParamYB("区属",GetSqlWhere());
            CustomGridList1.DataSource = dt;
            CustomGridList1.RecordCount = dt.Rows.Count;
            CustomGridList1.DataBind();
            
        }
        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            BindData();
        }
        protected string GetSqlWhere() 
        {
            string sqlWhere = string.Empty;
            if (_EluZSDataProvider.IsQZSBM(userid))
            {
                sqlWhere += @"And (Select (Case When tt.rolename='白下区征收部门' Then '秦淮区征收部门'
When tt.rolename='下关区征收部门' Then '鼓楼区征收部门' Else tt.rolename End) From Zs_Role Tt Where tt.id In 
(Select t.Roleid From Zs_User_In_Role t Where t.Userid Like '%" + userid + @"%')) Like 
'%' || (Case When keyname='下关区' Then '鼓楼区'  When keyname='白下区' Then '秦淮区' Else keyname End) || '%' ";
            }
            sqlWhere += "And keyname not in ('白下区','下关区') ";
            return sqlWhere;
        }
    }
}


